package com.hades.example.java.refactoring.after.c11.c11_10_form_template_method;

import java.util.ArrayList;
import java.util.List;

public class Customer {
    private String name;
    private List<Rental> _rentals = new ArrayList<>(); // 租借记

    public Customer(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void addRental(Rental arg) {
        _rentals.add(arg);
    }

    public List<Rental> getRentals() {
        return _rentals;
    }

    // 以ASCII 码打印报表
    public String statement() {
        return new TextStatement().value(this);
    }

    // 以HTML 格式输出报表
    public String htmlStatement() {
        return new HtmlStatement().value(this);
    }

    public double getTotalCharge() {
        double totalCharge = 0; // 总消费金。
        for (Rental each : _rentals) {
            totalCharge += each.getCharge(); // 取得一笔租借记。
        }
        return totalCharge;
    }

    public int getTotalFrequentRenterPoints() {
        int frequentRenterPoints = 0; // 常客积点
        for (Rental each : _rentals) {
            frequentRenterPoints = each.getFrequentRenterPoints();
        }
        return frequentRenterPoints;
    }
}
